<?php

namespace App\Models;

use App\Common\Traits\HasAgentRevenues;
use App\Common\Traits\HasAttachments;
use Illuminate\Database\Eloquent\SoftDeletes;

class AfterSaleOrder extends Base
{
    use SoftDeletes, HasAttachments, HasAgentRevenues;

    /**
     * 售后类型: 退货
     */
    const TYPE_RETURN = 1;

    /**
     * 售后类型: 重发货
     */
    const TYPE_HEAVY_SHIPMENT = 2;

    /**
     * 售后类型: 只退款
     */
    const TYPE_REFUND_ONLY = 3;

    /**
     * 售后类型: 补偿
     */
    const TYPE_MAKE_UP = 4;

    const TYPE_MAP = [
        self::TYPE_RETURN => '退货',
        self::TYPE_HEAVY_SHIPMENT => '重发货',
        self::TYPE_REFUND_ONLY => '只退款',
        self::TYPE_MAKE_UP => '补偿',
    ];

    /**
     * 售后状态: 待审核
     */
    const STATUS_PENDING_REVIEW = 1;

    /**
     * 售后状态: 跟进中
     */
    const STATUS_FOLLOWING_UP = 2;

    /**
     * 售后状态: 已通过
     */
    const STATUS_PASSED = 3;

    /**
     * 售后状态: 未通过
     */
    const STATUS_DID_NOT_PASS = 4;

    /**
     * 售后状态: 已取消
     */
    const STATUS_CANCELLED = 5;

    /**
     * 售后附件类型: 图片
     */
    const ATTACHMENT_TYPE_PICTURE = 1;

    /**
     * 售后附件类型: 视频
     */
    const ATTACHMENT_TYPE_VIDEO = 2;

    const STATUS_MAP = [
        self::STATUS_PENDING_REVIEW => '待审核',
        self::STATUS_FOLLOWING_UP => '跟进中',
        self::STATUS_PASSED => '已通过',
        self::STATUS_DID_NOT_PASS => '未通过',
        self::STATUS_CANCELLED => '已取消',
    ];

    public function order()
    {
        return $this->belongsTo(Order::class);
    }

    public function afterSaleOrderSkus()
    {
        return $this->hasMany(AfterSaleOrderSku::class);
    }

    public function supplier()
    {
        return $this->belongsTo(Supplier::class);
    }

    public function agent()
    {
        return $this->belongsTo(Agent::class);
    }

    public function client()
    {
        return $this->belongsTo(Client::class);
    }

    public function audit()
    {
        return $this->hasMany(AfterSaleOrderAudit::class);
    }

    /**
     * 快递信息
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
     */
    public function courierInformation()
    {
        return $this->morphMany(CourierInformation::class, 'deliverable');
    }
}
